export function isNumber(value) {
    return /^\d+$/.test(value);
}

export function outSize(bytes) {
    if (typeof bytes !== 'number' || !bytes) {
        return '0'
    }
    if (bytes < 1024)
        return bytes + ' byte'
    else if (bytes < 1048576)
        return bytesToKB(bytes)
    else if (bytes < 1073741824)
        return bytesToMB(bytes)
    return bytesToGB(bytes)
}

function bytesToKB(bytes) {
    return (bytes / 1024).toFixed(2) + ' kb'; // toFixed(2) 用于保留两位小数
}

function bytesToMB(bytes) {
    return (bytes / 1048576).toFixed(2) + ' MB';
}

function bytesToGB(bytes) {
    return (bytes / 1073741824).toFixed(3) + ' GB';
}

export function formatDate(timestamp) {
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = ("0" + (date.getMonth() + 1)).slice(-2);
    const day = ("0" + date.getDate()).slice(-2);
    const hours = ("0" + date.getHours()).slice(-2);
    const minutes = ("0" + date.getMinutes()).slice(-2);
    const seconds = ("0" + date.getSeconds()).slice(-2);
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}